package com.example.datastructure;

public class ArrayStack {
    private long[] a;
    private int size;
    private int top;

    public ArrayStack(int maxSize){
        this.size=maxSize;
        this.a=new long[size];
        this.top=-1;//表示空栈
    }

    public void push(long value){
        if (isFull()){
            System.out.println("栈已满！");
            return;
        }
        a[++top]=value;
    }
    public void peek(){
        if (isEmpty()){
            System.out.println("空栈");
        }
        System.out.println(a[top]);
    }
    public long pop(){
        if (isEmpty()){
            System.out.println("空栈");
            return 0;
        }
        return a[top--];
    }

    public boolean isFull() {
        return (top==size-1);
    }
    public int size(){
        return top+1;
    }
    public boolean isEmpty(){
        return (top==-1);
    }
}
